﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Quest
{
    // enhancement #1: Make the enemies smarter
    public partial class FormSetLevels : Form
    {
        // enhancement #1: Make the enemies smarter

        List<Type> allEnemies = new List<Type>();
        Dictionary<Type, Levels> enemiesLevels = new Dictionary<Type, Levels>();
        public FormSetLevels(List<Type> AllEnemies, ref Dictionary<Type, Levels> EnemiesLevels)
        {
            InitializeComponent();
            enemiesLevels = EnemiesLevels;
            allEnemies = AllEnemies;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            SetEnemiesLevel();
            //            Application.Exit();
            this.Close();
        }

        //private void UpdateEnemiesLevel()
        //{
        //    //EnemiesLevels.Clear();
        //    string nameToSearch;
        //    foreach (Type type in AllEnemies)
        //    {
        //        nameToSearch = (type.Name).ToString();
        //        // set Enemies Levels
        //        //foreach (ComboBox cb in this.tableLayoutPanel1.Controls.OfType<ComboBox>())
        //        foreach (ComboBox cb in this.tableLayoutPanel1.Controls.OfType<ComboBox>())
        //            if (cb.Name.Contains(nameToSearch))
        //            {
        //                enemiesLevels.Add(type, getLevel(cb.SelectedItem.ToString()));
        //                break;
        //            }
        //    }
        //}
        private void SetEnemiesLevel()
        {
            //EnemiesLevels.Clear();
            string nameToSearch;
            foreach (Type type in allEnemies)
            {
                nameToSearch = (type.Name).ToString();
                // set Enemies Levels
                foreach (ComboBox cb in this.tableLayoutPanel1.Controls.OfType<ComboBox>())
                    if (cb.Name.Contains(nameToSearch))
                    {
                        enemiesLevels.Add(type, getLevel(cb.SelectedItem.ToString()));
                        break;
                    }
            }
        }

        private Levels getLevel(string levelToSearch)
        {
            foreach (Levels level in Enum.GetValues(typeof(Levels)))
                if (level.ToString() == levelToSearch)
                    return level;
            return Levels.Low; // default. but this should be activated under coding bugs only
        }



    }
}
